home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / language / isetl.arc / qrec.t < prev    next >
Text File  |  1987-08-20  |  763b  |  28 lines

  1.        quick := func(list);
  2.             local i,p;
  3.  
  4.             if #list <= 1 then return list;
  5.             else
  6.             p := list(#list div 2);
  7.             return quick([i: i in list | i < p])
  8.                    + ([i: i in list | i = p])
  9.                    + quick([i: i in list | i > p]) ;
  10.             end;
  11.         end;
  12.  
  13.     quick([20,19..1]);
  14.     quick("qwertyuioplkjhgfdsazxcvbnm");
  15. $ worst case data is sorted
  16. quick([1..20]);
  17. quick([20,19..1]);
  18.  
  19. $random data is faster
  20. quick([25, 13, 14, 5, 6, 7, 22, 23, 24, 1, 2, 9, 27, 28, 34, 35, 26, 15,
  21. 37, 38, 40, 16, 17, 30, 31, 21, 10, 11, 18, 32, 33, 39, 29, 19, 3,
  22. 4, 8, 20, 12, 36]);
  23.  
  24. $of course, strings work too
  25. quick(["there", "is", "hardly", "any", "problem", "with", "using",
  26. "different", "types", "in", "subtle", "because", "the", "operators",
  27. "are", "polymorphic"]);
  28.